<html>
<head><meta charset="utf-8"><title>Better way to detect platforms with slow multiply/divide · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Better.20way.20to.20detect.20platforms.20with.20slow.20multiply.2Fdivide.html">Better way to detect platforms with slow multiply/divide</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="209342971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Better%20way%20to%20detect%20platforms%20with%20slow%20multiply/divide/near/209342971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Braden Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Better.20way.20to.20detect.20platforms.20with.20slow.20multiply.2Fdivide.html#209342971">(Sep 08 2020 at 03:34)</a>:</h4>
<p>While looking into an unrelated issue (<a href="https://github.com/rust-lang/rust/issues/66219">https://github.com/rust-lang/rust/issues/66219</a>) I noticed that the current way used to tell that a platform might have trouble with division/multiplication is to test it's pointer width, as least in core/src/slice/memchr.rs. See line 26.<br>
Is there some better way this could be set up? As there exist 32-bit platforms with slow divide/multiply, and 16-bit platforms with fast divide/multiply.</p>



<a name="209343072"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Better%20way%20to%20detect%20platforms%20with%20slow%20multiply/divide/near/209343072" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Braden Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Better.20way.20to.20detect.20platforms.20with.20slow.20multiply.2Fdivide.html#209343072">(Sep 08 2020 at 03:37)</a>:</h4>
<p>This feels like something that'd need a per-platform flag, though.</p>



<a name="209343221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Better%20way%20to%20detect%20platforms%20with%20slow%20multiply/divide/near/209343221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Better.20way.20to.20detect.20platforms.20with.20slow.20multiply.2Fdivide.html#209343221">(Sep 08 2020 at 03:41)</a>:</h4>
<p>this sounds hard because it's in libstd, not the compiler</p>



<a name="209343232"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Better%20way%20to%20detect%20platforms%20with%20slow%20multiply/divide/near/209343232" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Better.20way.20to.20detect.20platforms.20with.20slow.20multiply.2Fdivide.html#209343232">(Sep 08 2020 at 03:41)</a>:</h4>
<p>so it doesn't know about all the targets the compiler supports</p>



<a name="209343295"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Better%20way%20to%20detect%20platforms%20with%20slow%20multiply/divide/near/209343295" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Braden Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Better.20way.20to.20detect.20platforms.20with.20slow.20multiply.2Fdivide.html#209343295">(Sep 08 2020 at 03:42)</a>:</h4>
<p>Looking now, seems like target_pointer_width itself could do with some improvement... Not going to start two threads just yet, but looking in <a href="http://vec_deque.rs">vec_deque.rs</a> (alloc/src/collections) shows 3 separate pointer width checks used to calculate ZST capacity. And yea, that's an issue. The best way would for there to be some cfg checkable value, as I can imagine this being a nice-to-have for embedded developers, but that's a whole can of worms.</p>



<a name="209343503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Better%20way%20to%20detect%20platforms%20with%20slow%20multiply/divide/near/209343503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Braden Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Better.20way.20to.20detect.20platforms.20with.20slow.20multiply.2Fdivide.html#209343503">(Sep 08 2020 at 03:48)</a>:</h4>
<p>it looks like a const for the pointer width and type decls for the signed/unsigned pointer ints could be helpful (the latter would be, say, <code>type UPointer = u32</code> on 32-bit platforms.) But now i'm off-topic.</p>



<a name="209343518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Better%20way%20to%20detect%20platforms%20with%20slow%20multiply/divide/near/209343518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Braden Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Better.20way.20to.20detect.20platforms.20with.20slow.20multiply.2Fdivide.html#209343518">(Sep 08 2020 at 03:49)</a>:</h4>
<p>the latter specifically for tests. It feels like other cases could be refactored to use usize.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>